package com.everest.tribalapp;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Plik_form7 extends Activity implements OnClickListener
{

	private Button form7;
	private Button form7ba;
	private int value;
	private TextView plik_form7_qus1;
	private TextView plik_form7_qus2;
	private TextView plik_form7_qus3;
	private CheckBox plik_form7_ans2a;
	private CheckBox plik_form7_ans2b;
	private CheckBox plik_form7_ans3a;
	private CheckBox plik_form7_ans3b;
	private CheckBox plik_form7_ans3c;
	private CheckBox plik_form7_ans3d;
	private CheckBox plik_form7_ans3e;
	private CheckBox plik_form7_ans3f;
	private CharSequence[] MSG_VALUES_2={"Pasang stiker pada perangkat dan pintu","Tulis nomor Call Center"};
	private CharSequence[] MSG_VALUES_3={"Pengelola","Perangkat yg tersedia","Papan petunjuk","Saat mencoba telepon","Lingkungan sekitar","Sarana lainnya"};
	protected boolean[] selectVal2={false,false};
	protected boolean[] selectVal3={false,false,false,false,false,false};
	private EditText plik_form7_ans1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Plik_form7.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.plik_form7);
		form7=(Button)findViewById(R.id.plik_form7_b2);
		form7ba=(Button)findViewById(R.id.plik_form7_b1);
		decl();
		qus();
form7ba.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent in=new Intent(Plik_form7.this,Plik_form6.class);
				startActivity(in);
				Plik_form7.this.finish();
			}
		});
		form7.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent in=new Intent(Plik_form7.this,Plik_form8.class);
				startActivity(in);
				Plik_form7.this.finish();
			}
		});
	}
void decl()
{
	plik_form7_qus1=(TextView)findViewById(R.id.plik_form7_qus1);
	plik_form7_qus2=(TextView)findViewById(R.id.plik_form7_qus2);
	plik_form7_qus3=(TextView)findViewById(R.id.plik_form7_qus3);
	plik_form7_ans1=(EditText)findViewById(R.id.plik_form7_ans1);
	plik_form7_ans2a=(CheckBox)findViewById(R.id.plik_form7_che1a);
	plik_form7_ans2b=(CheckBox)findViewById(R.id.plik_form7_che1b);
	plik_form7_ans3a=(CheckBox)findViewById(R.id.plik_form7_che3a);
	plik_form7_ans3b=(CheckBox)findViewById(R.id.plik_form7_che3b);
	plik_form7_ans3c=(CheckBox)findViewById(R.id.plik_form7_che3c);
	plik_form7_ans3d=(CheckBox)findViewById(R.id.plik_form7_che3d);
	plik_form7_ans3e=(CheckBox)findViewById(R.id.plik_form7_che3e);
	plik_form7_ans3f=(CheckBox)findViewById(R.id.plik_form7_che3f);
	plik_form7_ans2a.setOnClickListener(this);
	plik_form7_ans2b.setOnClickListener(this);
	plik_form7_ans3a.setOnClickListener(this);
	plik_form7_ans3b.setOnClickListener(this);
	plik_form7_ans3c.setOnClickListener(this);
	plik_form7_ans3d.setOnClickListener(this);
	plik_form7_ans3e.setOnClickListener(this);
	plik_form7_ans3f.setOnClickListener(this);
}
void qus()
{
	plik_form7_qus1.setOnClickListener(new View.OnClickListener() {
		
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			value=R.string.plik_form7_qus1;
			toast_msg();
		}
	});
plik_form7_qus2.setOnClickListener(new View.OnClickListener() {
	
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			value=R.string.plik_form7_qus2;
			toast_msg();
		}
	});
plik_form7_qus3.setOnClickListener(new View.OnClickListener() {

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		value=R.string.plik_form7_qus3;
		toast_msg();
	}
});
}
public void toast_msg()
{
	LayoutInflater inflater = getLayoutInflater();

	View layout = inflater.inflate(R.layout.custom_toast,
			(ViewGroup) findViewById(R.id.custom_toast_layout_id));
	TextView text = (TextView) layout.findViewById(R.id.text);
	text.setText(value);
	Toast toast = new Toast(getApplicationContext());
	toast.setGravity(Gravity.BOTTOM, 0, 0);
	toast.setDuration(Toast.LENGTH_LONG);
	toast.setView(layout);
	toast.show();
}
private void msg_f7_ans_2()
{
	     Builder builder = new AlertDialog.Builder(this);
	     builder.setTitle("Answer");
	     builder.setMultiChoiceItems(MSG_VALUES_2, selectVal2,
	         new DialogInterface.OnMultiChoiceClickListener()
	     {
	           @Override
	           public void onClick(DialogInterface dialog, int which,
	               boolean isChecked) 
	           {
	             selectVal2[which] = isChecked;
	           }
	         });
	     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
	       @Override
	       public void onClick(DialogInterface dialog, int which) {
	         for (int i = 0; i <MSG_VALUES_2.length; i++) 
	         {
	           if (selectVal2[i]) 
	           {
	              if(i==0)
	 				{
	            	 
	            	  plik_form7_ans2a.setChecked(true);
					}
	 				else if(i==1)
	 				{
	 					plik_form7_ans2b.setChecked(true);
	 				}
	 			
	           }
	           else
	           {
	        	   if(i==0)
	 				{
	            	 
	        		   plik_form7_ans2a.setChecked(false);
					}
	 				else if(i==1)
	 				{
	 					plik_form7_ans2b.setChecked(false);
	 				}
	 				
	           }
	         }
	        }
	     });
	     builder.setNegativeButton("cancel",
	         new DialogInterface.OnClickListener() {
	           @Override
	           public void onClick(DialogInterface dialog, int which) {
	             dialog.dismiss();
	           }
	         });
	     AlertDialog alert = builder.create();
	     alert.show();
	   }
private void msg_f7_ans_3()
{
	     Builder builder = new AlertDialog.Builder(this);
	     builder.setTitle("Answer");
	     builder.setMultiChoiceItems(MSG_VALUES_3, selectVal3,
	         new DialogInterface.OnMultiChoiceClickListener()
	     {
	           @Override
	           public void onClick(DialogInterface dialog, int which,
	               boolean isChecked) 
	           {
	             selectVal3[which] = isChecked;
	           }
	         });
	     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
	       @Override
	       public void onClick(DialogInterface dialog, int which) {
	         for (int i = 0; i <MSG_VALUES_3.length; i++) 
	         {
	           if (selectVal3[i]) 
	           {
	              if(i==0)
	 				{
	            	 
	            	  plik_form7_ans3a.setChecked(true);
					}
	 				else if(i==1)
	 				{
	 					plik_form7_ans3b.setChecked(true);
	 				}
	 				else if(i==2)
	 				{
	 					plik_form7_ans3c.setChecked(true);
	 				}
	 				else if(i==3)
	 				{
	 					plik_form7_ans3d.setChecked(true);
	 				}
	 				else if(i==4)
	 				{
	 					plik_form7_ans3e.setChecked(true);
	 				}
	 				else if(i==5)
	 				{
	 					plik_form7_ans3f.setChecked(true);
	 				}
	           }
	           else
	           {
	        	   if(i==0)
	 				{
	            	 
	        		   plik_form7_ans3a.setChecked(false);
					}
	 				else if(i==1)
	 				{
	 					plik_form7_ans3b.setChecked(false);
	 				}
	 				else if(i==2)
	 				{
	 					plik_form7_ans3c.setChecked(false);
	 				}
	 				else if(i==3)
	 				{
	 					plik_form7_ans3d.setChecked(false);
	 				}
	 				else if(i==4)
	 				{
	 					plik_form7_ans3e.setChecked(false);
	 				}
	 				else if(i==5)
	 				{
	 					plik_form7_ans3f.setChecked(false);
	 				}
	 				
	           }
	         }
	        }
	     });
	     builder.setNegativeButton("cancel",
	         new DialogInterface.OnClickListener() {
	           @Override
	           public void onClick(DialogInterface dialog, int which) {
	             dialog.dismiss();
	           }
	         });
	     AlertDialog alert = builder.create();
	     alert.show();
	   }
@Override
public void onClick(View v) {
	if(v.getId()==plik_form7_ans2a.getId())
	{
		plik_form7_ans2a.setChecked(false);
		msg_f7_ans_2();
	}
	else if(v.getId()==plik_form7_ans2b.getId())
	{
		plik_form7_ans2b.setChecked(false);
		msg_f7_ans_2();
	}
	else if(v.getId()==plik_form7_ans3a.getId())
	{
		plik_form7_ans3a.setChecked(false);
		msg_f7_ans_3();
	}
	else if(v.getId()==plik_form7_ans3b.getId())
	{
		plik_form7_ans3b.setChecked(false);
		msg_f7_ans_3();
	}
	else if(v.getId()==plik_form7_ans3c.getId())
	{
		plik_form7_ans3c.setChecked(false);
		msg_f7_ans_3();
	}
	else if(v.getId()==plik_form7_ans3d.getId())
	{
		plik_form7_ans3d.setChecked(false);
		msg_f7_ans_3();
	}
	else if(v.getId()==plik_form7_ans3f.getId())
	{
		plik_form7_ans3f.setChecked(false);
		msg_f7_ans_3();
	}
	else if(v.getId()==plik_form7_ans3e.getId())
	{
		plik_form7_ans3e.setChecked(false);
		msg_f7_ans_3();
	}
	// TODO Auto-generated method stub
	
}

@Override
protected void onPause() {
	// TODO Auto-generated method stub
	super.onPause();
	SharedPreferences preferences=getSharedPreferences("plik_f7_details",MODE_PRIVATE);
	SharedPreferences.Editor editor=preferences.edit();
	editor.putString("7_1", plik_form7_ans1.getText().toString().trim());
	editor.putBoolean("7_2a",plik_form7_ans2a.isChecked());
	editor.putBoolean("7_2b",plik_form7_ans2b.isChecked());
	editor.putBoolean("7_3a",plik_form7_ans3a.isChecked());
	editor.putBoolean("7_3b",plik_form7_ans3b.isChecked());
	editor.putBoolean("7_3c",plik_form7_ans3c.isChecked());
	editor.putBoolean("7_3d",plik_form7_ans3d.isChecked());
	editor.putBoolean("7_3e",plik_form7_ans3e.isChecked());
	editor.putBoolean("7_3f",plik_form7_ans3f.isChecked());
	editor.commit();
	
}

@Override
protected void onResume() {
	// TODO Auto-generated method stub
	super.onResume();
	SharedPreferences preferences=getSharedPreferences("plik_f7_details",MODE_PRIVATE);
	plik_form7_ans1.setText(preferences.getString("7_1", ""));
	plik_form7_ans2a.setChecked(preferences.getBoolean("7_2a",false));
	plik_form7_ans2b.setChecked(preferences.getBoolean("7_2b",false));
	plik_form7_ans3a.setChecked(preferences.getBoolean("7_3a",false));
	plik_form7_ans3b.setChecked(preferences.getBoolean("7_3b",false));
	plik_form7_ans3c.setChecked(preferences.getBoolean("7_3c",false));
	plik_form7_ans3d.setChecked(preferences.getBoolean("7_3d",false));
	plik_form7_ans3e.setChecked(preferences.getBoolean("7_3e",false));
	plik_form7_ans3f.setChecked(preferences.getBoolean("7_3f",false));
}
}
